package com.vint.leetcode;

public class Leetcode223 {
  public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    return area(A,B,C,D) + area(E,F,G,H) - sameArea(A,B,C,D,E,F,G,H);

  }
  public int sameArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    if(C<=E)return 0;
    if(H<=B)return 0;
    if(E<=A&&F<=B&&C<=G&&D<=H) return area(A,B,C,D);
    if(E>=A&&F>=B&&C>=G&&D>=H)return area(E,F,G,H);
    return area(E, B, C, H);
  }
  public int area(int a, int b, int c, int d) {
    int height = b > d ? b - d : d - b;
    int width = a > c ? a -c : c - a;
    return height * width;
  }
  public static void main(String[] args){
    Leetcode223 leetcode223 = new Leetcode223();
    leetcode223.computeArea(-2,-2,2,2,-4,3,-3,4);
    System.out.println("done;");
  }
}
